{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "读取通达信自选股文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['0300788', '0300405', '0003042', '0000421', '0000157', '0000830', '1603408', '0002290', '0002357', '0002884', '0300015', '0002532', '1600919', '1603960', '1600377', '1603969', '0000571', '0000570', '0000554', '1601288', '1600350', '0001872', '1600012', '0300175', '1510050', '1601500', '0000897', '1600900', '0000153', '1603883', '1600724', '1600243', '1600655', '1600906', '0002926', '0001308', '0002670', '1603586', '0300350', '1601688', '1600825', '1600864', '1600621', '0002059', '1603663', '1601872', '1605500', '0000400', '0001318', '1601000', '0000762', '2871478', '1600188', '0301061', '0000408', '1600592', '0000155', '1600796', '1601919', '1603712', '0002150', '0000039']\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# 读取文本文件\n",
    "file_path = 'D:\\\\自选股.EBK'  # 替换为你的文件路径\n",
    "data = pd.read_csv(file_path, delimiter='\\t', header=None, dtype=str)\n",
    "# 将DataFrame转换为字符串列表\n",
    "string_list = data.iloc[:, 0].tolist()\n",
    "print(string_list) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['300788', '300405', '003042', '000421', '000157', '000830', '603408', '002290', '002357', '002884', '300015', '002532', '600919', '603960', '600377', '603969', '000571', '000570', '000554', '601288', '600350', '001872', '600012', '300175', '510050', '601500', '000897', '600900', '000153', '603883', '600724', '600243', '600655', '600906', '002926', '001308', '002670', '603586', '300350', '601688', '600825', '600864', '600621', '002059', '603663', '601872', '605500', '000400', '001318', '601000', '000762', '871478', '600188', '301061', '000408', '600592', '000155', '600796', '601919', '603712', '002150', '000039']\n"
     ]
    }
   ],
   "source": [
    "# 去掉每个字符串的第一个字符\n",
    "modified_string_list = [s[1:] for s in string_list]\n",
    "print(modified_string_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "读取通达信自选股文件，并转换成掘金的读取格式"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['SZSE.300788', 'SZSE.300405', 'SZSE.003042', 'SZSE.000421', 'SZSE.000157', 'SZSE.000830', 'SHSE.603408', 'SZSE.002290', 'SZSE.002357', 'SZSE.002884', 'SZSE.300015', 'SZSE.002532', 'SHSE.600919', 'SHSE.603960', 'SHSE.600377', 'SHSE.603969', 'SZSE.000571', 'SZSE.000570', 'SZSE.000554', 'SHSE.601288', 'SHSE.600350', 'SZSE.001872', 'SHSE.600012', 'SZSE.300175', 'SHSE.510050', 'SHSE.601500', 'SZSE.000897', 'SHSE.600900', 'SZSE.000153', 'SHSE.603883', 'SHSE.600724', 'SHSE.600243', 'SHSE.600655', 'SHSE.600906', 'SZSE.002926', 'SZSE.001308', 'SZSE.002670', 'SHSE.603586', 'SZSE.300350', 'SHSE.601688', 'SHSE.600825', 'SHSE.600864', 'SHSE.600621', 'SZSE.002059', 'SHSE.603663', 'SHSE.601872', 'SHSE.605500', 'SZSE.000400', 'SZSE.001318', 'SHSE.601000', 'SZSE.000762', 'SHSE.871478', 'SHSE.600188', 'SZSE.301061', 'SZSE.000408', 'SHSE.600592', 'SZSE.000155', 'SHSE.600796', 'SHSE.601919', 'SHSE.603712', 'SZSE.002150', 'SZSE.000039']\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "# 读取文本文件\n",
    "file_path = 'D:\\\\自选股.EBK'  # 替换为你的文件路径\n",
    "data = pd.read_csv(file_path, delimiter='\\t', header=None, dtype=str)\n",
    "# 将DataFrame转换为字符串列表\n",
    "string_list = data.iloc[:, 0].tolist()\n",
    "# 替换第一个字符\n",
    "modified_string_list = [\n",
    "    'SHSE.' + s[1:] if s.startswith(('1', '2')) else 'SZSE.' + s[1:] if s.startswith('0') else s\n",
    "    for s in string_list\n",
    "]\n",
    "print(modified_string_list) "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "将 symbols_list 中的所有股票代码字符串用逗号 , 连接起来，形成一个新的字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "SHSE.833454,SHSE.837046,SHSE.835670,SZSE.300667,SHSE.512000,SHSE.600547,SHSE.512200,SHSE.517520,SHSE.512010,SZSE.301353,SZSE.300994,SZSE.000901,SHSE.600052,SZSE.002937,SHSE.603679,SHSE.512880,SZSE.300067,SZSE.301395,SZSE.301106,SZSE.300638,SZSE.002889,SZSE.000636,SZSE.002338,SZSE.301308,SHSE.512480,SHSE.512760,SZSE.000037,SZSE.000400,SHSE.688100,SHSE.600268,SZSE.159934,SZSE.000537,SZSE.300433,SHSE.603507,SZSE.002249,SZSE.000063,SHSE.601126,SHSE.600064,SHSE.601928\n"
     ]
    }
   ],
   "source": [
    "symbols_string = ','.join(modified_string_list)\n",
    "print(symbols_string)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
